#include <iostream>
#include <algorithm>
#define NUM 31
using namespace std;

int FibStep(int n)
{
    int fib[3] = {0,1,1};
    if(n <= 2){
        return 0;
    }
    int fibright = 0;
    int fibleft = 1, f = 2;
    while(fibright < n){   
        fibright = f + fibleft;   // 记录第一个大于等于n的fibright
        fibleft = f;        // 记录第一个大于等于n的fibleft
        f = fibright;      
    }
    return min(n-fibleft, fibright-n);
}

/*  //1.双重循环
int fib[NUM] = {0, 1, 1};   //第31个fib = 1346296

int FibStep(int n, bool x)
{
    int cnt = 0, flag = 0;
    for(int i = n; i >=0 || i <= NUM ; (x && --i) || ++i){ 
         //true求x-1的步数，false求x+1的步数
        for(int j = 0; j < NUM; ++j){
            if(i == fib[j]){
                flag = 1;
                break;
            }
        }
        if(flag){ break; }
        cnt++;   //步数
    }
    return cnt;
}
*/

/*  //双重循环傻
int FibStep(int n)
{
    int cnt1 = 0, cnt2 = 0;
    for(int i = n; i >= 0; --i){
        int flag = 0;
        for(int j = 0; j < NUM; ++j){
            if(fib[j] == i){
                flag++;
                break;
            }
        }
        if(flag){
            break;
        }
        cnt1++;
    }
    for(int i = n; ; ++i){
        int flag = 0;
        for(int j = 0; j < NUM; ++j){
            if(fib[j] == i){
                flag++;
                break;
            }
        }
        if(flag){
            break;
        }
        cnt2++;
    }
    return min(cnt1, cnt2);
}
*/
    
int main()
{
    int n;
    cin >> n;
    /*  //双重循环
    for(int i = 3; i < NUM; ++i){
        fib[i] = fib[i-1] + fib[i-2];
    }
  //  cout << fib[n];
    cout << min(FibStep(n, true), FibStep(n,false));
    */
    
    cout << FibStep(n);
    return 0;
}